canAjaxCallback

Description

Fires before every Ajax callback made to the server.

Discussion

Fires when an Ajax callback is made to the server. You can use this event to authorize the callback action. The e variable contains information about the callback you can reference in your Xbasic code.

If you want to prevent the Ajax callback from executing, set the e.authorized variable to .f.. This will also trigger the onAjaxCallbackNotAllowed client-side event.

If you set e.authorized to .t. or leave it blank, the callback will be executed.

JavaScript can be returned from the function using the e.javascript variable. The JavaScript returned using e.javascript will be executed regardless of whether or not the callback is cancelled.

Available Variables in the 'e' Object

Several variables are available for reading or setting in the canAjaxCallback event. These variables are properties of the e object. The variables in the e object include:

Variable
Description
e.tmpl

The definition of the UX Component.

e.action

The Ajax callback action name.

e.callbackFunctionName

The name of the Ajax callback function being called.

Your code can set the following variables in the e object:

Variable
Description
e.javascript

Javascript to return to the client and execute.

e.authorized

A .t. or .f. value. If you do not set the value for this property, then authorized is assumed to be .t.. If authorized is .f., the callback is cancelled and the onAjaxCallbackNotAllowed client-side event is triggered on the client.

When working in Live Preview you can get the names of the simulated security groups using this variable: e.tmpl.Livepreview_permissions_friendly

When running in a real application, you can get the names of the security groups for the logged in using using: Context.Security.GetUserRoles()

Example

function canAjaxCallback as v (e as p)

    if (e.callbackFunctionName == "doNotDoCallback") then
        e.authorized = .f.
    else
        e.authorized = .t.
    end if

end function

See Also